package MapAndSet.Map;

import java.util.*;

public class TestTreeMap {
    public static void main(String[] args) {
        Map<String,Integer> map = new TreeMap<>();//key value type
        TreeMap<String,Integer> map2 = new TreeMap<>();
        map.put("b",3);
        map.put("c",2);
        map.put("v",5);
        int val = map.getOrDefault("d",-1);
        System.out.println(val);
        val = map.get("c");
        System.out.println(val);
        Set<String> set = map.keySet();//收集key
        Collection<Integer> collection=map.values();//收集value
        Set<Map.Entry<String,Integer>> entries = map.entrySet();//搜索树上每一个节点放的都是Map.Entry
        for (Map.Entry<String,Integer> entry :entries) {
            System.out.println("key:"+entry.getKey()+" value:"+entry.getValue());
        }
        for (Map.Entry<String,Integer> entry :map.entrySet()) {
            System.out.println(entry.getKey()+entry.getValue());
        }
        System.out.println("testLine");
    }
}
